/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.view;

import com.model.Anggota;
import com.model.Perpustakaan;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author tashiba
 */
public class PanelTambahAnggota extends JPanel {

    private JLabel labelKodeAnggota;
    private JTextField textKodeAnggota;
    private JLabel labelNama;
    private JTextField textNama;
    private JButton tombolSimpan;
    private JButton tombolBatal;

    public PanelTambahAnggota() {

        setLayout(null);

        JLabel judul = new JLabel("Form Tambah Anggota");
        judul.setBounds(150, 20, 150, 20);
        this.add(judul);

        labelKodeAnggota = new JLabel("ID Anggota");
        labelKodeAnggota.setBounds(50, 70, 100, 20);
        this.add(labelKodeAnggota);

        textKodeAnggota = new JTextField();
        textKodeAnggota.setBounds(150, 70, 100, 20);
        this.add(textKodeAnggota);

        labelNama = new JLabel("Nama Anggota");
        labelNama.setBounds(50, 100, 100, 20);
        this.add(labelNama);

        textNama = new JTextField();
        textNama.setBounds(150, 100, 200, 20);
        this.add(textNama);

        JPanel save = new JPanel();
        tombolSimpan = new JButton();
        tombolSimpan.setBounds(150, 150, 80, 20);
        tombolSimpan.setText("Simpan");
        save.add(tombolSimpan);
        this.add(tombolSimpan);

        JPanel cancel = new JPanel();
        tombolBatal = new JButton();
        tombolBatal.setBounds(260, 150, 80, 20);
        tombolBatal.setText("Batal");
        cancel.add(tombolBatal);
        this.add(tombolBatal);

        tombolSimpan.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tombolSimpanAction();
            }
        });
        tombolBatal.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });


    }

    public void tombolSimpanAction() {
        Anggota anggota = new Anggota();
        try {
            anggota.setIdAnggota(textKodeAnggota.getText());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        anggota.setNama(textNama.getText());

        Perpustakaan.tambahAnggota(anggota);
       JOptionPane.showMessageDialog(this, "ANGGOTA"
                    +"\nJudul      : "+anggota.getIdAnggota()
                    +"\nID Koleksi : "+anggota.getNama());

    }
}
